import 'dart:convert';

import 'package:convert/convert.dart';

abstract class EthMethod {
  late String name;

  EthMethod(this.name);

  List<dynamic> packData();
}

class SignPersonalMethod extends EthMethod {
  late String message;

  late String address;

  SignPersonalMethod(this.message, this.address) : super('personal_sign');

  @override
  List<dynamic> packData() {
    final newMessage = hex.encoder.convert(utf8.encode(message));
    print("新数据" + newMessage);
    return ["0x$newMessage", address];
  }
}

class SignTypedMethod extends EthMethod {
  late String address;

  late String data;

  SignTypedMethod(this.address, this.data) : super("eth_signTypedData");

  @override
  List<dynamic> packData() {
    return [address, data];
  }
}

class SignTransactionMethod extends EthMethod {
  late String from;
  late String to;
  late String gasPrice; //可为null
  late String gasLimit; //不可为null
  late String data; //0x开头的签名数据
  late String value; //0x开头的金额

  SignTransactionMethod(
      this.from, this.to, this.gasPrice, this.gasLimit, this.data, this.value)
      : super("eth_signTransaction");

  @override
  List<dynamic> packData() {
    throw UnimplementedError();
  }
}
